package system

import (
	"5title_gin/internal/service/system"
	"5title_gin/pkg/utils/http"
	"github.com/gin-gonic/gin"
)

type MenuAPI struct {
	service *system.MenuService
}

func NewMenuAPI() *MenuAPI {
	return &MenuAPI{
		service: system.NewMenuService(),
	}
}

// GetMenuList 获取菜单列表
// @Tags 菜单管理
// @Summary 获取菜单列表
// @Description 获取所有菜单，返回树形结构
// @Param token header string true "token"
// @Router /api/menu/list [get]
// @Produce json
// @Success 200 {object} http.Response
func (api *MenuAPI) GetMenuList(c *gin.Context) {
	roleID, exists := c.Get("roleID")
	if !exists {
		http.FailWithMsg("获取角色ID失败", c)
		return
	}
	menus, err := api.service.GetMenuList(roleID.(uint))
	if err != nil {
		http.FailWithMsg("获取菜单列表失败", c)
		return
	}
	http.OkWithData(menus, c)
}
